package com.cn.ycy;

import com.cn.ycy.interceptor.SecurityInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * springbootapplication 告诉spring这是一个配置类 功能和application.xml一样
 */
// SpringBootApplication启动时会默认扫描主类当前包及子包
@SpringBootApplication(scanBasePackages = {"com.cn.ycy"})
//@SpringBootApplication(scanBasePackageClasses = {CookieController.class})
@ImportResource(locations = {"classpath:springcontext.xml"})
@MapperScan(basePackages = {"com.cn.ycy.mapper"})
@Slf4j
public class SpringbootApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootApplication.class, args);
    }

    public void addInterceptors(InterceptorRegistry registry) {
//    List<String> list = this.securityProperties.getWhiteUrlList();
//    if (list != null) {
//      String[] arr = new String[list.size()];
//      for (int i = 0; i < list.size(); i++) {
//        arr[i] = String.valueOf(list.get(i));
//      }
//      SecurityRegistry.me().excludePathPatterns(arr);
//    }
        registry.addInterceptor((HandlerInterceptor) new SecurityInterceptor())
                .addPathPatterns(new String[]{"/**"})
//            .excludePathPatterns(SecurityRegistry.me().getExcludePatterns())
        ;
        log.info("===Power-starter===SecurityWebAutoConfiguration===>exclude patterns registed...");
    }

}

